<template>
	<view>
		<view style="padding: 20rpx;">
			<u-swiper :list="list1" height="200"></u-swiper>
		</view>
		<view style="padding: 20rpx;">
			<u-search placeholder="搜索" @click="goSousuo" :showAction="false" disabled></u-search>
		</view>


		<view class="product_box">
			<view class="class_list" v-for="item,index in index_data" :key="item._id">
				<view class="title">
					<view style="width: 80rpx;"></view>
					<view style="font-weight: bold;display: flex;align-items: center;gap:8rpx">
						<image :src="item.icon" style="width: 28rpx;height: 28rpx;" mode="widthFix"></image>
						<view>{{item.title}}</view>
					</view>
					<view style="display: flex;align-items: center;font-size: 30rpx;color: #939393;" @click="goSousuo">
						<view>更多</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="product_list" v-if="item.product_list.length">
					<view class="product_item" v-for="product,product_index in item.product_list" :key="product._id" @click="goInfo(product)">
						<image class="image" :src="product.image" mode="aspectFill"></image>
						<view class="product_bottom">
							<view class="product_title">{{product.title}}</view>
							<view class="product_info">
								<view>
									<view style="color: #ff0000;font-weight: bold;">
										<span style="font-size: 20rpx;">￥</span> <span>{{product.price}}</span>
									</view>
									<view style="color: #939393;font-size: 20rpx;">库存{{product.inventory}}</view>
								</view>
								
								<view @click.stop="changeCurrentInfo(product)">
										<u-icon name="shopping-cart" size="26" color="#ff0000" ></u-icon>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else>
					<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png" text="该分类暂无商品~">
					</u-empty>
				</view>
			</view>
		</view>
		
		<sku-buy :show="show" :currentInfo="current_info" @close="show = false"></sku-buy>
	</view>
</template>


<script>
	import skuBuy from '@/components/skuBuy.vue'
	var vk = uni.vk;
	export default {
		components:{
			skuBuy
		},
		data() {
			// 页面数据变量
			return {
				show:false,
				current_info:null,
				list1: [
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				],
				index_data: null,
				// init请求返回的数据
				// 表单请求数据
				form1: {

				},
				scrollTop: 0,
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			vk = uni.vk;
			this.options = options;
			this.init(options);
			
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {

		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		async onShow() {
			this.getIndexData()
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {

		},
		// 监听 - 点击右上角转发时
		onShareAppMessage(options) {

		},
		// 函数
		methods: {
			changeCurrentInfo(item){
				console.log("发UC看")
				this.current_info = item
				this.show  =true
			},
			// 页面数据初始化函数
			init(options) {},
			async getIndexData() {
				let res = await vk.callFunction({
					url: 'client/pages/index/pub/index_data',
					title: '芜湖'
				});
				console.log(res)
				this.index_data = res.data.rows
			},
			goSousuo() {
				uni.navigateTo({
					url: '/pages/index/search/search'
				})
			},
			goInfo(item){
				uni.navigateTo({
					url:`/pages/product/product?product_id=${item._id}`
				})
			}
		},
		// 监听器
		watch: {

		},
		// 计算属性
		computed: {

		}
	}
</script>
<style lang="scss" scoped>
	.product_box {

		.class_list {
			padding: 25rpx;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20rpx;

			}

			.product_list {
				gap:20rpx;
				display: grid;
				grid-template-columns: repeat(3, 220rpx);
				justify-content: space-between;

				.product_item {
					box-shadow: 0 0 10rpx rgba(200, 200, 200, 0.5);
					border-radius: 10rpx;
					overflow: hidden;


					.image {
						width: 220rpx;
						height: 220rpx;
					}

					.product_bottom {
						padding: 12rpx;

						.product_title {
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-size: 26rpx;
						}

						.product_info {
							display: flex;
							justify-content: space-between;
							align-items: flex-end;
							margin-top: 15rpx;
						}
					}

				}
			}

		}
	}
</style>
